package com.matrix.draft.jvm.jmm;

/**
 * JMM有序性
 * 指令重排
 */
public class JITOrdered {


    int num = 0;
    boolean ready = false;

    // 线程1执行
    public void action1(Result r){
        if(ready){
            r.r = num + num;
        }else{
            r.r = 1;
        }
    }

    // 线程2执行
    public void action2(){
        num = 2;
        ready = true;
    }

    private class Result{
        private int r;
    }

}
